package com.ph.irp.base.voucher.action;

import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.ph.irp.base.voucher.service.VoucherService;
import com.ph.irp.model.PBaseVoucher;

public class VoucherAction extends ActionSupport {
	private String FORWARD = null;
	private List<PBaseVoucher> voucherList = null;
	private PBaseVoucher voucherModel = null;
	private VoucherService voucherService;
	private String successString;
	private Object[] rowlist;
	private List<Integer> list = new ArrayList<Integer>();


	public List<PBaseVoucher> getVoucherList() {
		return voucherList;
	}

	public void setVoucherList(List<PBaseVoucher> voucherList) {
		this.voucherList = voucherList;
	}

	public PBaseVoucher getVoucherModel() {
		return voucherModel;
	}

	public void setVoucherModel(PBaseVoucher voucherModel) {
		this.voucherModel = voucherModel;
	}

	public VoucherService getVoucherService() {
		return voucherService;
	}

	public void setVoucherService(VoucherService voucherService) {
		this.voucherService = voucherService;
	}

	public Object[] getRowlist() {
		return rowlist;
	}

	public void setRowlist(Object[] rowlist) {
		this.rowlist = rowlist;
	}

	public List<Integer> getList() {
		return list;
	}

	public void setList(List<Integer> list) {
		this.list = list;
	}


	/*
	 * 查询所有数据
	 */
	public String showVoucherList() throws Throwable {
		voucherModel = null;
		voucherList = voucherService.getVoucherList(voucherModel);
		if (voucherList != null)
			FORWARD = "success";
		else
			FORWARD = "input";
		return FORWARD;
	}

	/*
	 * 打开新增页面
	 */
	public String showAddVoucher() {
		voucherModel = null;
		FORWARD = "success";
		return FORWARD;
	}

	/*
	 * 打开修改页面
	 */
	public String showEditVoucher() throws Throwable {
		voucherModel = voucherService.getVoucherById(Integer
				.valueOf((String) rowlist[0]));
		if (voucherModel != null)
			FORWARD = "success";
		else
			FORWARD = "input";
		return FORWARD;
	}

	/*
	 * 新增
	 */
	public String addVoucher() throws Throwable {
		voucherService.addVoucher(voucherModel);
		voucherModel = null;
		FORWARD = "success";
		return FORWARD;
	}

	/*
	 * 修改
	 */
	public String editVoucher() throws Throwable {
		voucherService.updateVoucher(voucherModel);
		voucherModel = null;
		FORWARD = "success";
		return FORWARD;
	}

	/*
	 * 查询
	 */
	public String getVoucher() throws Throwable {
		if (voucherModel.getVoucherName() != null) {
			voucherList = voucherService.getByName(voucherModel
					.getVoucherName());
			FORWARD = "success";
		} else {
			FORWARD = "input";
		}
		voucherModel = null;
		return FORWARD;
	}

	/*
	 * 删除币别
	 */
	public String deleteVoucher() throws Throwable {
		for (int i = 0; i < rowlist.length; i++) {
			voucherService.deleteVoucher(Integer.parseInt((String) rowlist[i]));
		}
		FORWARD = "success";
		return FORWARD;
	}

	// /*
	// * 查询所有满足条件数据,包括无条件查询
	// */
	// public String select() throws Throwable {
	// voucherList = voucherService.getVoucherList(voucherModel);
	// voucherModel = null;
	// if (voucherList != null) {
	// FORWARD = "success";
	//
	// } else {
	// FORWARD = "display";
	// }
	// return FORWARD;
	// }
	//
	// /*
	// * 新增记录
	// */
	// public String add() throws Throwable {
	// if (voucherModel.getVoucherId() != 0) {
	// voucherService.updateVoucher(voucherModel);
	// voucherModel = null;
	// } else {
	// voucherService.addVoucher(voucherModel);
	// voucherModel = null;
	// }
	// FORWARD = "display";
	// return FORWARD;
	// }
	//
	// /*
	// * 打开新增或修改页面
	// */
	// public String addInput() {
	// FORWARD = "addInput";
	// voucherModel = null;
	// return FORWARD;
	// }
	//
	// /*
	// * 修改币别
	// */
	// public String update() throws Throwable {
	// voucherModel = voucherService.getVoucherById(Integer
	// .valueOf((String) rowlist[0]));
	// FORWARD = "addInput";
	// return FORWARD;
	// }
	//
	// /*
	// * 删除记录
	// */
	// public String delete() throws Throwable {
	// int result = 0;
	// for (int i = 0; i < rowlist.length; i++) {
	// result = voucherService.deleteVoucher(Integer
	// .valueOf((String) rowlist[i]));
	// }
	// if (result == 1) {
	// FORWARD = "display";
	// } else {
	// setSuccessString("不存在该凭证字");
	// FORWARD = "error";
	// }
	// return FORWARD;
	// }

	public String getSuccessString() {
		return successString;
	}

	public void setSuccessString(String successString) {
		this.successString = successString;
	}

}
